package cn.com.bluemoon.daps.sync.core.sync.sql.mysql;

import cn.com.bluemoon.daps.sync.core.sync.sql.SqlStrBuilder;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

/**
 * mysql增加列
 *
 * @author Jarod.Kong
 * @date 2021/6/4 15:30
 */
@Setter
@Getter
@AllArgsConstructor
@NoArgsConstructor
public class MysqlAddColumnDefinition implements IKeyAddBlackQuote {
    private MysqlColumnDefinition columnDefinition;
    private String preColumnName;
    private Boolean addBlackQuote = true;

    @Override
    public String toString() {
        SqlStrBuilder sb = new SqlStrBuilder()
                .appendWS("add column")
                .append(getColumnDefinition().toString());
        if (preColumnName != null) {
            sb.appendWS("after");
            if (addBlackQuote) {
                sb.appendBQ(preColumnName);
            }else {
                sb.append(preColumnName);
            }
        } else {
            sb.appendWS("first");
        }
        return sb.toString();
    }
}
